<template>
  <div class="app-container">
    <el-row :gutter="20" class="toolbar" type="flex" justify="space-between">
      <!-- 左侧组合 -->
      <el-col :span="16">
        <el-row :gutter="15">
          <el-col :span="10">
            <el-input
                v-model="searchKey"
                placeholder="输入应用名称搜索"
                @keyup.enter.native="handleSearch">
              <el-button slot="append" icon="el-icon-search" @click="handleSearch"></el-button>
            </el-input>
          </el-col>
        </el-row>
      </el-col>

    </el-row>
    <!-- 数据表格 -->
    <el-table
        :data="appList"
        border
        stripe
        style="width: 100%"
        class="data-table">
      <el-table-column
          type="index"
          label="序号"
          width="60"
          align="center">
      </el-table-column>

      <el-table-column
          prop="appName"
          label="应用名称"
          min-width="150">
      </el-table-column>

      <el-table-column
          prop="creator"
          label="创建人"
          width="120">
      </el-table-column>

      <el-table-column
          prop="createTime"
          label="创建时间"
          width="180">
      </el-table-column>

      <el-table-column
          prop="remark"
          label="应用描述"
          min-width="200">
      </el-table-column>

      <el-table-column
          label="操作"
          width="200"
          align="center">
        <template #default="{row}">
          <el-button
              type="text"
              size="small"
              @click="handleConfig(row)">查看用户信息
          </el-button>
        </template>
      </el-table-column>
    </el-table>

    <!-- 分页 -->
    <el-pagination
        class="pagination"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="currentPage"
        :page-sizes="[10, 20, 50]"
        :page-size="pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total">
    </el-pagination>

  </div>

</template>

<script>
import {queryAppPage} from '@/api/gateway-app'

export default {
  data() {
    return {
      selectedApp: '',
      searchKey: '',
      currentPage: 1,
      pageSize: 10,
      total: 0,
      appList: [],
    }
  },
  mounted() {
    this.loadAppData()
  },
  methods: {
    // 加载数据方法
    async loadAppData() {
      try {
        const params = {
          page: this.currentPage,
          size: this.pageSize,
          keywords: this.searchKey,
        }

        const {data} = await queryAppPage(params)
        this.appList = data.records
        this.total = data.total
        // 同步分页信息（根据接口实际情况调整）
        this.currentPage = data.current
        this.pageSize = data.size
      } catch (error) {
        console.error('数据加载失败:', error)
      }
    },
    // 修改后的处理方法
    handleSearch() {
      this.currentPage = 1 // 搜索时重置到第一页
      this.loadAppData()
    },
    handleSizeChange(val) {
      this.pageSize = val
      this.loadAppData()
    },
    handleCurrentChange(val) {
      this.currentPage = val
      this.loadAppData()
    },
    async handleConfig(row) {
      this.$router.push({name: 'auth-user-info', query: {id: row.id}})
    },
  }
}
</script>

<style scoped>

/* 新增样式 */
.el-dialog__body {
  padding: 20px 30px;
}

.el-form-item {
  margin-bottom: 22px;
}

.el-textarea {
  resize: vertical;
}

.toolbar {
  margin-bottom: 20px;
}

.search-input {
  margin-right: 10px;
}

.data-table {
  margin-top: 15px;
}

.pagination {
  margin-top: 20px;
  text-align: right;
}

.text-right {
  text-align: right;
}

.detail-dialog .el-form-item {
  margin-bottom: 15px;
}

.detail-dialog .el-form-item span {
  font-weight: bold;
  color: #333;
}

.detail-dialog .dialog-footer {
  text-align: right;
  padding: 10px 0;
}

.detail-dialog .el-dialog__body {
  padding: 20px 30px;
  background-color: #f9f9f9;
  border-radius: 8px;
}
</style>